﻿using UnityEngine;
using System.Collections;
using System;
using DataProto;

public class MonoSingle<T> : MonoBehaviour where T :MonoSingle<T> {

    private static T instance;
    public static T SG
    {
        get
        {
            return instance;
        }
    }

    void OnApplicationQuit()
    {
        if (instance != null)
            instance = null;
    }

    void Awake()
    {
        instance = GetComponent<T>();
        OnAwake();
    }
    protected virtual void OnAwake() { }
}

public class NorSingleton<T>
{
    protected static readonly T instance = Activator.CreateInstance<T>();
    public static T Instance
    {
        get { return instance; }
    }
    protected NorSingleton()
    {
        OnInit();
    }
    protected  virtual void OnInit() {}
}